import Vue from 'vue'
import App from './App.vue'
import router from './router'

import axios from 'axios'
import VueAxios from 'vue-axios'


import 'lib-flexible/flexible'

import {
  Tabbar,
  TabbarItem,
  Search,
  Swipe,
  SwipeItem,
  Sidebar,
  SidebarItem,
  GoodsAction,
  GoodsActionIcon,
  GoodsActionButton,
  Icon,
  NavBar,
  Form,
  Field,
  Button,
  Popup,
  Toast,
  SwipeCell,
  Card,
  Checkbox,
  CheckboxGroup,
  SubmitBar,
  Empty,
  Uploader,
  Cell,
  CellGroup,
  AddressList,
  AddressEdit,
  Tab,
  Tabs,
  ActionSheet,
  PasswordInput,
  NumberKeyboard
} from 'vant';

Vue.use(VueAxios, axios)
Vue
  .use(Tabbar)
  .use(TabbarItem)
  .use(Search)
  .use(Swipe)
  .use(SwipeItem)
  .use(Sidebar)
  .use(SidebarItem)
  .use(GoodsAction)
  .use(GoodsActionButton)
  .use(GoodsActionIcon)
  .use(Icon)
  .use(NavBar)
  .use(Form)
  .use(Field)
  .use(Button)
  .use(Popup)
  .use(Toast)
  .use(SwipeCell)
  .use(Card)
  .use(Checkbox)
  .use(CheckboxGroup)
  .use(SubmitBar)
  .use(Empty)
  .use(Uploader)
  .use(Cell)
  .use(CellGroup)
  .use(AddressList)
  .use(AddressEdit)
  .use(Tab)
  .use(Tabs)
  .use(ActionSheet)
  .use(PasswordInput)
  .use(NumberKeyboard)

Vue.config.productionTip = false

// 添加请求拦截器
// axios.interceptors.request.use(function (config) {
//     Toast.loading({
//       message: '加载中...',
//       forbidClick: true,
//       duration: 0,
//     });
//   return config;
// }, function (error) {
//   return Promise.reject(error);
// });
// // 添加响应拦截器
// axios.interceptors.response.use(function (response) {
//     Toast.clear();
//   return response;
// }, function (error) {
//     Toast.clear();
//   return Promise.reject(error);
// });

// 时间过滤器
Vue.filter('timeData', value => {
  // 
  if (!value) {
    return '';
  }
  if (Object.prototype.toString.call(value) !== "[Object Date]") {
    value = new Date(value);
  }
  var year = value.getFullYear();
  var month = value.getMonth() + 1;
  month = month >= 10 ? month : '0' + month;
  var date = value.getDate();
  date = date >= 10 ? date : '0' + date;
  var hours = value.getHours();
  hours = hours >= 10 ? hours : '0' + hours;
  var minutes = value.getMinutes();
  minutes = minutes >= 10 ? minutes : '0' + minutes;
  var seconds = value.getSeconds();
  seconds = seconds >= 10 ? seconds : '0' + seconds;
  return `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')